package com.kinggm.service.impl;

import com.kinggm.mapper.UserMapper;
import com.kinggm.model.User;
import com.kinggm.service.UserService;
import com.kinggm.util.PageInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

@Service
@Slf4j
public class UserServiceImpl implements UserService {

    @Resource
    private UserMapper userMapper;

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void insertData() {
        for (int i = 1; i <= 20; i++) {
            User user = new User();
//            user.setId(i);
            user.setName("秀逗" + i);
            userMapper.insert(user);
            log.info("插入成功 id={}",user.getId());
        }
    }

    @Override
    public List<User> searchByPage(PageInfo pageInfo, User user) {
        List<User> users = userMapper.searchByPage(pageInfo, user);
        return users;
    }



}
